package com.ailight.smart.api.controller;

import com.ailight.smart.api.entity.command.LightModelCommand;
import com.ailight.smart.api.entity.dto.LightGearDTO;
import com.ailight.smart.api.service.LightOperationService;
import com.ailight.smart.common.result.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 朱海鹏
 * @Package: com.ailight.smart.admin.controller
 * @Project: ai-light
 * @date: 2025/5/21 23:10
 * @description :
 */
@RestController
@RequestMapping("/api/v1/control/light")
@RequiredArgsConstructor
public class LightMqttController {

    private final LightOperationService lightOperationService;

    /**
     * 调节模式以及挡位
     *
     * @param command 入参
     * @return 结果
     */
    @PutMapping("/operation/light")
    public Result<String> operLight(@RequestBody LightModelCommand command) {
        command.check();
        String msg = lightOperationService.operation(command);
        return Result.success(msg);
    }

    /**
     * 获取当前光照已经挡位
     *
     * @return 结果
     */
    @GetMapping("/sensor/data")
    public Result<LightGearDTO> getLatestSensorData() {
        return Result.success(lightOperationService.getLatestSensorData());
    }

    /**
     * 开关灯
     *
     * @param state 状态
     * @return 结果
     */
    @GetMapping("/modify/state")
    public Result<String> modifyLightState(@RequestParam(value = "state",
            required = false, defaultValue = "1") Integer state) {
        return Result.success( lightOperationService.modifyLightState(state));
    }
}
